/**
 * 
 */
package com.java.test.user.mapper;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;

import com.java.test.user.dto.DrawingChannelInfo;

/**
 * @author Administrator
 *
 */
@Component
public class DrawingChannelMapper {

	@Autowired
	private JdbcTemplate jdbcTemplate;

	public List<DrawingChannelInfo> selectdrawingchannelList(DrawingChannelInfo info) {

		String sql = "select * from member_drawingchannel where 1=1 ";

		if (info.getDrawingTypeId() != 0) {
			sql += " and drawing_typeid='" + info.getDrawingTypeId() + "'";
		}
		sql += " order by sort desc";
		List<DrawingChannelInfo> list = jdbcTemplate.query(sql, new DrawingChannelInfo());

		return list;

	}

	public int insertdrawingchannelInfo(DrawingChannelInfo info) {
		String sql = "insert into member_drawingchannel(img_url,add_time,channel_name,drawing_typeid,content,sort,add_people)values(?,?,?,?,?,0,?)";
		int i = jdbcTemplate.update(sql, info.getImgUrl(), info.getAddTime(), info.getChannelName(),
				info.getDrawingTypeId(), info.getContent(), info.getAddPeople());
		return i;
	}

	public DrawingChannelInfo selectdrawingchannelInfobyId(DrawingChannelInfo info) {

		String sql = "select * from member_drawingchannel where id=?";
		DrawingChannelInfo obj = null;
		try {
			obj = jdbcTemplate.queryForObject(sql, new DrawingChannelInfo(), info.getId());
		} catch (Exception e) {
			return null;
		}

		return obj;

	}

	public int updatedrawingchannelInfo(DrawingChannelInfo info) {
		String sql = "update member_drawingchannel set channel_name=?,img_url=?,drawing_typeid=?,content=? where id=?";
		int i = jdbcTemplate.update(sql, info.getChannelName(), info.getImgUrl(), info.getDrawingTypeId(),
				info.getContent(), info.getId());
		return i;
	}

	public int updatedrawingchannelsortInfo(DrawingChannelInfo info) {
		String sql = "update member_drawingchannel set sort=? where id=?";
		int i = jdbcTemplate.update(sql, info.getSort(), info.getId());
		return i;
	}

	public int deletedrawingchannelInfo(DrawingChannelInfo info) {
		String sql = "delete from  member_drawingchannel where id=?";
		int i = jdbcTemplate.update(sql, info.getId());
		return i;
	}

	public int selectdrawingchanbyTypeId(int typeid) {
		String sql = "select count(*) from member_drawingchannel where drawing_typeid=?";
		int obj = jdbcTemplate.queryForObject(sql, Integer.class, typeid);
		return obj;
	}

}
